/*
 * PASTAflip.h
 *
 *  Created on: Nov 23, 2009
 *      Author: abhishek
 */

#ifndef PASTAFLIP_H_
#define PASTAFLIP_H_

#include "Headers.h"
#include "Node.h"
#include "EdgeMap.h"
#include "BestBFS.h"
#include "Edge.h"



class PASTAflip {
public:
	PASTAflip();
	virtual ~PASTAflip();

	void loadData();
	int maxPossibleObjective(){return maxPossibleObjective_;}

	int currentObjective();
	void runPASTAFlip();

private:
	int signBetweenEdges(string key);
	void signBetweenEdgesIs(string key, int sign);

	int numBadMinusGoodCycles(string key);
	void addGoodCycle(string key);
	void addBadCycle(string key);

	Node* nodeIsPresent(int nodeId);
	void createNode(int id);
	void updateSuccessorList(int node1, int node2);
	void printData();
	int randomNumber();
	void resetBFS();
	void resetVisitedStatusInNodes();

	void doBFS(int rootId, bool enableMetadata);
	int findBestBFS();
	void runGreedyEdgeFlip();
	void BFSPushInHeap(priority_queue<Edge*, vector<Edge*>, Comparator >& heap);
	void BFSCluster();
	Edge* findEdge(string key);
	void writeData();
	int currentScore();
	void totalSuccessorEntries();
	void copyToCurrentSuccessorList();
	void removeFromCurrentSuccessors(int id, int id2);
	void computeCurrentScore();
	int computeCurrentScoreInMemory();
	void updateEdgesInCycles(string key, vector<string> edges);

	map<int, Node*> nodeMap_ ;
	map<int, vector<int> > successorList_ ;
	map<int, vector<int> > currentSuccessorList_ ;

	int numNodes_ ;
	map<string, int> edgeSignMap_ ;
	map<string, Edge*> edgeBadCyclesMap_ ;

//	EdgeMap* edgeMap_ ;
	BestBFS* bestBFS_ ;

	int* clusterMap_ ; // output of the correlation clustering
	int maxPossibleObjective_ ;
	int currentScore_ ;

};

#endif /* PASTAFLIP_H_ */
